import { useUserStore } from "@/store/module/user";
import router from "@/router";

/*
 *
 *
 *  退出登陆
 *
 */
export function loginOut(befor: () => void, alfe: () => void) {
  const userStore = useUserStore();
  // 参数一
  befor && befor();
  // 删除token
  localStorage.removeItem("token");
  // 删除仓库 pinia
  userStore.updateMenus([]);
  userStore.username = "";
  // 清除动态路由 c
  const allrouter = router.getRoutes();
  allrouter.forEach((item) => {
    if (item.name != "login" && item.name) {
      router.removeRoute(item.name);
    }
  });
  // 跳转到login
  router.push("login");

  // 参数二
  alfe && alfe();
}
